package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.GoodsEvaluateEnum;
import com.frogs.system.web.exception.RequestIllegalException;
import com.frogs.system.web.api.request.Request;

/**
 * 商品评价内容请求参数类
 *
 * @author lijian
 * @version 2014年3月18日 - 上午10:31:17
 */
public class GoodsEvaluateListRequest extends Request {

	/**
	 * 账号ID
	 */
	private int userId;
	/**
	 * 商品Id
	 */
	private int goodsId;
	
	
	/**套餐id*/
	private Integer mealId;
	
	/**
	 * 排序<br />
	 * 1-时间，2-赞数量，3-药师优先, 4-默认, 5-推荐
	 */
	private Integer sort;
	
	/** 
	 * 当前页码 
	 */
	private int pageNum = 1;
	/**
	 * 每页条数 
	 */
	private int numPerPage = 10;
	
	public GoodsEvaluateListRequest(){
		
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.goodsId = requestInfo.getIntParameter(ApiUrlParamEnum.goodsId.getParamName(), 0);
		this.mealId = requestInfo.getIntParameter(ApiUrlParamEnum.mealId.getParamName(), 0);
		this.sort = requestInfo.getIntParameter(ApiUrlParamEnum.sort.getParamName(), GoodsEvaluateEnum.SORT_COMBINATION.getId());
		this.pageNum = requestInfo.getIntParameter(ApiUrlParamEnum.pageNo.getParamName(),1);
		this.numPerPage = requestInfo.getIntParameter(ApiUrlParamEnum.pageSize.getParamName(), 10);
		if (userId < 1 && goodsId < 1 && mealId < 1) {
			throw new RequestIllegalException("error userId: " + userId + ", error goodsId or mealId: " + goodsId+","+mealId);
		}
		if (userId > 0 && goodsId > 0) {
			throw new RequestIllegalException("error userId: " + userId + " error goodsId: " + goodsId);
		}
		if (sort > 5) {
			throw new RequestIllegalException("error sort:" + sort);
		}
		if (pageNum < 1) {
			throw new RequestIllegalException("error pageNum:" + pageNum);
		}
		if (numPerPage < 1) {
			throw new RequestIllegalException("error numPerPage:" + numPerPage);
		}
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public Integer getMealId() {
		return mealId;
	}

	public void setMealId(Integer mealId) {
		this.mealId = mealId;
	}
	
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getNumPerPage() {
		return numPerPage;
	}

	public void setNumPerPage(int numPerPage) {
		this.numPerPage = numPerPage;
	}

}
